package com.lv.phuotbacnam.toolbox;

import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;

import com.lv.phuotbacnam.R;

import java.util.Calendar;

/**
 * Utility class for window creation
 */
public class WindowUtils {

    /**
     * Build a generic progress dialog
     * @param context Context to build the dialog from
     * @return Progress dialog
     */
    public static Dialog buildProgressDialog(Context context){
        Dialog dialog = new Dialog(context, android.R.style.Theme_NoTitleBar);
        dialog.setContentView(R.layout.dialog_progress);
        Drawable d = new ColorDrawable(Color.BLACK);
        d.setAlpha(180);
        dialog.getWindow().setBackgroundDrawable(d);
        return dialog;
    }

    public static Dialog buildDateSelectionDialog(Context context, Calendar calendar,
                                                  DatePickerDialog.OnDateSetListener onDateSetListener){
        return new DatePickerDialog(context, onDateSetListener,
                calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
    }

    public static Dialog buildTimeSelectionDialog(Context context, Calendar calendar,
                                                  TimePickerDialog.OnTimeSetListener onTimeSetListener){
        return new TimePickerDialog(context, onTimeSetListener, calendar.get(Calendar.HOUR_OF_DAY), 0, true);
    }

    public static Dialog buildGenericDialog(Context context, String title, String message,
                                            String negativeButtonText, DialogInterface.OnClickListener negativeButtonOnClickListener,
                                            String positiveButtonText, DialogInterface.OnClickListener positiveButtonOnClickListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context, AlertDialog.THEME_HOLO_LIGHT);
        builder.setTitle(title)
                .setMessage(message);

        if (negativeButtonText != null) {
            builder.setNegativeButton(negativeButtonText, negativeButtonOnClickListener);
        }
        if (positiveButtonText != null) {
            builder.setPositiveButton(positiveButtonText, positiveButtonOnClickListener);
        }

        return builder.create();
    }
}
